package com.zs.dbmonitor.config;

import io.debezium.engine.DebeziumEngine;

import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author ZhaoShuai
 * @version 1.0
 * @description: TODO
 * @date 2024/6/20 22:00
 */
@Data
@Slf4j
public class DebeziumServerBootstrap implements InitializingBean, SmartLifecycle {
    private final Executor executor = Executors.newSingleThreadExecutor();

    private DebeziumEngine<?> debeziumEngine;

    @Override
    public void start() {
        log.info("debeziumEngine is start");
        executor.execute(debeziumEngine);
    }
    @SneakyThrows
    @Override
    public void stop() {
        log.info("debeziumEngine is stop");
        debeziumEngine.close();
    }
    @Override
    public boolean isRunning() {
        return false;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(debeziumEngine, "debeziumEngine must not be null");
    }
}
